package com.cjy.address.service.impl;

import com.cjy.address.service.AddressService;
import com.base.common.persistent.dao.CompoundsMapper;
import com.base.common.persistent.dao.ProvinceMapper;
import com.base.common.persistent.dao.VillageConfigMapper;
import com.base.common.persistent.model.Compounds;
import com.base.common.persistent.model.Province;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

@Service("addressService")
public class AddressServiceImpl implements AddressService {

	@Resource
	private CompoundsMapper compoundsMapper; 
	
	@Resource
	private ProvinceMapper provinceMapper;

	@Resource
	private VillageConfigMapper villageConfigMapper;
	
	@Override
	public List<Province> getAllAddress() {
		return provinceMapper.queryAllAddress();
	}

	@Override
	public List<Compounds> getCompoundsByDistrictId(int districtId) {
		List<Compounds> compoundses = compoundsMapper.queryCompoundsByDistrictId(districtId);
        List<Integer> untilRegisteCompoundsIDList = villageConfigMapper.getUntilRegisteCompoundsIDList();
        Stream<Compounds> compoundsStream = compoundses.stream().filter(item -> untilRegisteCompoundsIDList.contains(item.getId()));
        return compoundsStream.collect(Collectors.toList());
	}

	@Override
	public Object queryCompoundsByCategory(int category) {
		return compoundsMapper.queryCompoundsByCategory(category);
	}

}
